const express=require('express')
const app=express()
const cors=require('cors')
const bodyParser=require('body-parser')
const validIsLogin=require('./middleware/index')
const menu=require('./routers/menu')
const main=require('./routers/main')
const area =require('./routers/area')
const upload =require('./routers/upload')
const user=require('./routers/user')
const login=require('./routers/login')
const product=require('./routers/product')
const overview=require('./routers/overview')
const swaggerInstall = require('./utils/swagger')// 引入swagger
app.use(express.static('./data/upload'))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: true}));
app.use(cors({
    origin: '*', // 默认允许所有来源
    methods: ['GET', 'POST', 'PUT', 'DELETE'], // 控制允许的方法
    allowedHeaders: ['Content-Type', 'Authorization'] // 控制允许的请求头
}));
swaggerInstall(app) // 注册swagger
app.use('/api/login',login)
app.use(validIsLogin)
app.use('/api/menu',menu)
app.use('/api/main',main)
app.use('/api/area',area)
app.use('/api/upload',upload)
app.use('/api/product',product)
app.use('/api/user',user)
app.use('/api/overview',overview)
app.use(function(err,req,res,next){
    console.info(err.stack)
    res.status('500').send('服务端出错了')
})

app.listen('3030',function(){
    console.log('服务器正在监听3030端口')
})
